class demo { public static void main(String args[]) { System.out.println(" before call" ); test(8,2); System.out.println(" after call" ); System.out.println(" program end" ); } public static void test( int a , int b ) { int c=0; try { if( b == 0) throw new ArithmeticException("Value of b is Zero"); System.out.println("before expression..."); c= a/b; System.out.println("after expression"); } catch(ArithmeticException er) { System.out.println("error message : "+er); c=1; } System.out.println(" Result is :"+c ); } }
before call before expression... after expression Result is :4 after call program end
class demo { public static void main(String args[]) { System.out.println(" before call" ); test(8,0); System.out.println(" after call" ); System.out.println(" program end" ); } public static void test( int a , int b ) { int c=0; try { if( b == 0) throw new ArithmeticException("Value of b is Zero"); System.out.println("before expression..."); c= a/b; System.out.println("after expression"); } catch(ArithmeticException er) { System.out.println("error message : "+er); c=1; } System.out.println(" Result is :"+c ); } }
Before call Error message : value of b is Zero Result is 1 After call Program end
[ AccecssSpecifier ] [Modifier] methodName( datatype arg1 , . . ) throws ExceptionList { Statement ------------- return value ; }